package com.smart.web.controller.user.watches;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.smart.common.constant.URLEnum;
import com.smart.common.utils.bean.BeanUtils;
import com.smart.system.domain.AreaLocation;
import com.smart.system.domain.Employee;
import com.smart.system.domain.EmployeeTrajectory;
import com.smart.system.domain.dto.DeviceDataDto;
import com.smart.system.domain.dto.DeviceDataDtoPolice;
import com.smart.system.domain.dto.LocationInfo;
import com.smart.system.domain.dto.Watches;
import com.smart.system.domain.enums.AlarmType;
import com.smart.system.service.IEmployeeTrajectoryService;
import com.smart.system.service.IWatchesService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/devices")
public class WatchesController{

    @Autowired
    private IWatchesService watchersService;

    @GetMapping(value = "/receivedata")
    public Integer receivedata(HttpServletRequest request) throws Exception {
        URLEnum urlEnum = URLEnum.fromUrl(request.getParameter("action"));
        switch (urlEnum) {
                case SENSOR:
                    //心律数据,或者是心跳模式

                    DeviceDataDto andSet = BeanUtils.create(DeviceDataDto.class, request);
                    //电量为空则为心律数据,不为空则为心跳数据
                    if (andSet.getBattery()==null) {
                        //心率数据
                        System.err.println("心律数据");
                    }else{
                        //心跳数据
                        System.err.println("心跳数据");
                    }
                    watchersService.sensor(andSet);
                break;
                case SUBMITSPORT:
                    //运动数据
                    System.err.println("运动数据");
                    break;
                case SUBMITBLOODGLUCOSE:
                    //血糖数据
                    System.err.println("血糖数据");
                    break;
                case SUBMITSLEEP:
                    //睡眠数据
                    System.err.println("睡眠数据");
                    break;
                case SUBMITLOCATION:
                    //定位数据
                    System.err.println("定位数据");
                    watchersService.submitLocation(request);
                    break;
                case POLICE:
                    //报警数据
                    DeviceDataDtoPolice police = BeanUtils.create(DeviceDataDtoPolice.class, request);
                    watchersService.police(police);
                    System.err.println("报警数据");
                break;
                default:
        }
        return 1;
    }
    @PostMapping(value = "/receivedata")
    public Integer receivedataPost(@RequestBody Watches params){
        URLEnum urlEnum = URLEnum.fromUrl(params.getAction());
        switch (urlEnum) {
            case CHAT:
                //聊天数据
                return watchersService.chat(params);
            default:
        }
        return 1;
    }
}
